home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / DELPHI / VIMVCL23.ZIP / DEMO2S.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-04-19  |  5.7 KB  |  227 lines

  1. unit Demo2s;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Grids, viminbox, VimSess,
  8.   Menus, vim;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     VimSession1: TVimSession;
  13.     StringGrid1: TStringGrid;
  14.     Memo1: TMemo;
  15.     attachmentsList: TListBox;
  16.     toList: TListBox;
  17.     ccList: TListBox;
  18.     newcomp1: TVimInbox;
  19.     Label1: TLabel;
  20.     Label2: TLabel;
  21.     Label3: TLabel;
  22.     Memo2: TMemo;
  23.     procedure StringGrid1Click(Sender: TObject);
  24.     procedure attachmentsListDblClick(Sender: TObject);
  25.     procedure StringGrid1DrawCell(Sender: TObject; Col, Row: Longint;
  26.       Rect: TRect; State: TGridDrawState);
  27.     procedure FormActivate(Sender: TObject);
  28.     procedure StringGrid1DblClick(Sender: TObject);
  29.     procedure doGridDraw(forceDraw:boolean);
  30.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  31.   private
  32.     { Private declarations }
  33.   public
  34.     { Public declarations }
  35. {
  36.     newComp:TVimAddressBook;
  37.     newComp1:TVimInbox;
  38.     }
  39.   end;
  40.  
  41. var
  42.   Form1: TForm1;
  43.  
  44. implementation
  45.  
  46. {$R *.DFM}
  47. procedure TForm1.StringGrid1Click(Sender: TObject);
  48. var
  49.   i:integer;
  50.   s:string;
  51. begin
  52.   if stringGrid1.cells[1,0] = '' then
  53.     exit;
  54.   with newcomp1 do begin
  55.     getMessage(inboxContents.count-TStringGrid(sender).row);
  56.     {setMessageAsRead(inboxContents.count-TStringGrid(sender).row);}
  57.     memo1.lines.assign(messageLines);
  58.     toList.items.assign(toNames);
  59.     ccList.items.assign(CC);
  60.     if attachments.count <> 0 then
  61.       for i := 0 to attachments.count-1 do begin
  62.         str(TVimAttachment(attachments.objects[i]).size,s);
  63.         attachmentsList.items.add(attachments.strings[i]+' '+s+' bytes');
  64.       end
  65.     else
  66.       attachmentsList.clear;
  67.   end;
  68. end;
  69.  
  70. procedure TForm1.attachmentsListDblClick(Sender: TObject);
  71. var
  72.   lb:TLIstBox;
  73.   i:integer;
  74.   s:string;
  75. begin
  76.   lb := TListBox(Sender);
  77.   i := lb.itemIndex;
  78.   newcomp1.saveAttachment(i,'C:\');
  79. end;
  80.  
  81. procedure TForm1.StringGrid1DrawCell(Sender: TObject; Col, Row: Longint;
  82.   Rect: TRect; State: TGridDrawState);
  83. var
  84.   lRow, lCol:longint;
  85. begin
  86.   lRow := row;
  87.   lCol := col;
  88.   with (Sender as TStringGrid) do
  89.     with Canvas do begin
  90.       if (bool(stringGrid1.objects[0, row])) and
  91.          (stringGrid1.rowCount <> 0) and
  92.          (row > 0) then begin
  93.         brush.color := clAqua;
  94.         font.color := clBlack;
  95.       end else begin
  96.         if lrow = 0 then begin
  97.           brush.color := stringgrid1.fixedcolor;
  98.           font.color := clBlack;
  99.         end else begin
  100.           brush.color := clWhite;
  101.           font.color := clBlack;
  102.         end;
  103.       end;
  104.       fillRect(rect);
  105.       TextRect(Rect, Rect.Left + 3, Rect.Top + 3, cells[lcol, lrow]);
  106.   end;
  107. end;
  108.  
  109. procedure TForm1.doGridDraw(forceDraw:boolean);
  110. function NewTextWidth(fntFont : TFont; const sString : OpenString) :
  111.   integer;
  112. var
  113.   fntSave : TFont;
  114. begin
  115.   result := 0;
  116.   fntSave := Application.MainForm.Font;
  117.   Application.MainForm.Font := fntFont;
  118.   try
  119.     result := Application.MainForm.Canvas.TextWidth(sString);
  120.   finally
  121.     Application.MainForm.Font := fntSave;
  122.   end;
  123. end;
  124.  
  125. function iCalcGridWidth
  126.   (
  127.   sg : TStringGrid { the grid to meaure }
  128.   )
  129.   : integer; { the "exact" width }
  130.  
  131. const
  132.   cMEASURE_CHAR   = '0';
  133.   iEXTRA_COL_PIX  = 4;
  134.   iINDICATOR_WIDE = 11;
  135. var
  136.   i, iColumns, iRows, iColWidth, t : integer;
  137. begin
  138.   iColumns := 0;
  139.   result := GetSystemMetrics(SM_CXVSCROLL);
  140.   with sg do
  141.     for iColumns := 0 to colCount- 1 do begin
  142.       iColWidth := 0;
  143.       for iRows := 0 to rowCount - 1 do begin
  144.         t := NewTextWidth(sg.Font, cells[iColumns,iRows]);
  145.         if t > iColWidth then
  146.         iColWidth := t;
  147.       end;
  148.       if goVertLine in sg.Options
  149.         then inc(iColWidth);
  150.       ColWidths[iColumns] := iColWidth;
  151.     end;
  152. end;
  153. var
  154.   i:integer;
  155.   k:integer;
  156.   s:string;
  157. begin
  158.   if vimsession1.active = false then
  159.     vimsession1.active := true;
  160.   if newcomp1.active = true then begin
  161.     if not forceDraw then
  162.       exit;
  163.   end else begin
  164.     newComp1.scanInboxOnACtivate := false;
  165.     newcomp1.active := true;
  166.     newComp1.scanInbox;
  167.   end;
  168.   with stringGrid1, newcomp1 do begin
  169.     rowCount := newcomp1.Inboxcontents.count+2;
  170.     cells[4,0] := 'Subject';
  171.     cells[3,0] := 'Author';
  172.     cells[2,0] := 'Date';
  173.     cells[1,0] := 'Priority';
  174.     k:=1;
  175.     for i:= Inboxcontents.count-1 downto 0 do begin
  176.       s := inboxcontents.strings[i];
  177.       cells[4,k] := inboxcontents.strings[i];
  178.       cells[3,k] := TVimInboxMsg(inboxcontents.objects[i]).From;
  179.       cells[2,k] := DateToStr(TVimInboxMsg(inboxcontents.objects[i]).date);
  180.       case TVimInboxMsg(inboxcontents.objects[i]).priority of
  181.         low :s:='Low';
  182.         normal:s:='Normal';
  183.         urgent:s:='Urgent';
  184.       end;
  185.       cells[1,k] := s;
  186.       str(k,s);
  187.       cells[0,k] := s;
  188.       objects[0,k] := TObject(TVimInboxMsg(inboxcontents.objects[i]).msgUnRead);
  189.       inc(k);
  190.     end;
  191.   end;
  192.   iCalcGridWidth(stringGrid1);
  193. end;
  194.  
  195. procedure TForm1.FormActivate(Sender: TObject);
  196. begin
  197.   doGridDraw(FALSE);
  198. end;
  199.  
  200. procedure TForm1.StringGrid1DblClick(Sender: TObject);
  201. VAR N : Word;
  202. begin
  203.   if stringGrid1.cells[1,0] = '' then
  204.     exit;
  205.   with newcomp1 do begin
  206.     getMessage(inboxContents.count-TStringGrid(sender).row);
  207.     deleteMessage(inboxContents.count-TStringGrid(sender).row);
  208.     with TStringGrid(sender) do begin
  209.       if RowCount-1 = FixedRows then
  210.         Exit;
  211.       {move rows up}
  212.       for N := Row to RowCount-2 do
  213.         Rows[N] := Rows[N+1];
  214.       RowCount := RowCount-1;
  215.       Rows[RowCount].Clear;
  216.     end;
  217.   end;
  218. end;
  219.  
  220. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  221. var i:integer;
  222. begin
  223. i:=1  ;
  224. end;
  225.  
  226. end.
  227.